# -*- coding: utf-8 -*-
# @Author  :Zhaowwen
# @Time    : 2021/7/6 23:41
# @Function: #
import requests
import jsonpath
import json

url = 'https://map.tianditu.gov.cn/api/services?mn=GetServerListByPage&isShown=1&toTime=&keyname=serviceindex&keywords=&isTop=1&pageSize=12&state=1&searchText=&fromTime=&pageNum=1&sort=desc&isAvailable='
response =requests.get(url)
html_str = response.content.decode()

# 把json格式字符串转换成python对象
jsonobj = json.loads(html_str)

# 从根节点开始，匹配name节点
citylist = jsonpath.jsonpath(jsonobj,'$..districtid')

fp = open('city.txt','wb')

content = json.dumps(citylist, ensure_ascii=False)

fp.write(content.encode('utf-8'))
fp.close()
